/**
 * @file      thread.h
 * @copyright Copyright (c) 2018, ZCW Co., Ltd. All Rights Reserved.
 * @brief     brief
 * @author    caiwang213@qq.com
 * @date      2017-05-31 11:28:11
 *
 * @note
 *  thread.h defines
 */
#ifndef __THREAD_H__
#define __THREAD_H__
#include "mutex.h"

namespace log4x
{
class LOG4X_API Thread
{
typedef void* (*routine)(void* , int);

public:
    Thread();
    virtual ~Thread();

    int                start();
    void               stop();

    void               detach();
    bool               active();

    void               sleep(int ms, int per = 50);
    void               setEntry(routine func, void*  data = NULL, int id = 0);

protected:
    virtual void       run();

protected:
    static void      * entry(void* data, int id);

private:
    bool               m_active;
    Mutex              m_mtx;

    THREAD             m_trd;
    routine            m_func;
    void             * m_data;
    int                m_id;
};
}

#endif
